var objectA;
var objectB;
var baaa;

function Animator(method, duration, updateInterval) {

	this.time = 0;
	this.duration = duration;
	this.updateInterval = updateInterval;

}

Animator.prototype.start = function() {

	if (this.animation == null) {
		eval("this.animation = setInterval(\"this.update('" + this.getMethod + "',"
				+ this.getDuration() + ")\", 1000); ");
	} else {
		clearInterval(this.animation);
	}
}

Animator.prototype.update = function() {

	if (this.getTime() >= this.getDuration()) {
		this.stop();
	} else {
		eval(this.getMethod + "();");
	}
	this.setTime() = this.getTime() + 1;
}

Animator.prototype.stop = function() {
	alert("stoppping");
	this.setTime(0);
	clearInterval(this.animation);
}



Animator.prototype.test = function() {
	alert("test");
	
	baaa = setInterval("testm()",1000); 
	
	
}


Animator.prototype.testm = function() {
	alert("testm");
	clearInterval(baaa);
}



function Animator(object, method, duration, updateInterval) {

	this.time = 0;
	this.object = object;
	this.method = method;
	this.duration = duration;
	this.updateInterval = updateInterval;

	this.setUpdateInterval = function(value) {
		this.updateInterval = value;
	}

	this.setDuration = function(value) {
		this.duration = value;
	}

	this.setObject = function(value) {
		this.object = value;
	}

	this.setMethod = function(value) {
		this.method = value;
	}

	this.setTime = function(value) {
		this.time = value;
	}

	this.getDuration = function() {
		return this.duration;
	}

	this.getUpdateInterval = function() {
		return this.updateInterval;
	}

	this.getMethod = function() {
		return this.method;
	}

	this.getObject = function() {
		return this.object;
	}

	this.getTime = function() {
		console.log("bsaffsaffsfasa" + this.time);
		return this.time;
	}

	this.start = function() {
		var dsa = this.getMethods(this.getObject());
		console.log("Call: " + dsa);
		console.log("ddd:" + dsa[5]);

			/*
			 * var that = this; if (this.interval == null) { this.interval =
			 * setInterval(function() { that.update(); },
			 * this.getUpdateInterval());
			 *  } else { clearInterval(this.interval); }
			 * 
			 */

	}

	this.update = function() {

		if (this.getTime() >= this.getDuration()) {
			this.stop();
		} else {
			console.log(this.getObject());

			// eval(this.getObject()+"."+this.getMethod() + ";");
		}
		this.setTime(this.getTime() + 1);
	}

	this.stop = function() {
		console.log("stoppping");
		this.setTime(0);
		clearInterval(this.interval);
	}

	this.getMethods = function(obj) {
		var methods = new Array();

		for (var s in obj) {
			if (typeof(obj[s]) == "function") {
				methods[methods.length] = s;
			}
		}

		return methods
	}

}




/*
 
var output = true;
function testMethod() {
	if (output) {
		console.log("baaaaaaaaaa");
		output = false;
	}
}

function getMethods(obj) {

	for (var s in obj) {
		if (typeof(obj[s]) == "function") {
			// console.log(s);
			if (s == "getTime") {
				return obj[s];
			}
		}
	}

	return null;
}

function testTarget() {
	console.log("targetRUN");
}

function testInvoke(object, target) {
	var method = getMethods(object);
	console.log("invoke:" + method);
	console.log("invoke:" + typeof(methods));
	// methods[5].apply(this,new Array());
}

function testObject() {
	var objectB = new Animator(this, 'testMethod', 10, 100);
	testInvoke(objectB, "getTime");
}

function testCallObject() {
	var objectB = new Animator(this, 'testMethod', 10, 100);

	var objectA = new Animator(objectB, 'getTime', 10, 100);
	objectA.start();

}

*/
